<template>
  <div class="app">
    <myNavbar title="商品分类"></myNavbar>
    <div class="header" @click.stop=''>
      <div class="search_input_content" @click="searchClick">
        <!-- <div class="search_input"> -->
        <icon class="icon" content="tb-search" fontSize="38"></icon>
        <text class="search_input_content-text">请输入商品名</text>
        <!-- </div> -->
      </div>
    </div>
    <!-- <tabbar v-if="sellerLoaded" class="tabbar" :tabPages="tabPages" :eeui="tabConfig"></tabbar> -->
    <div class="app-inner">
      <scroller class="menu" show-scrollbar="false">
        <div v-for="(item, index) in firstLevelInfo" :key="index" :class="[item.isSelsected? 'menu-item-active' : 'menu-item']"
             @click="firstLevelTap(item.id)">
          <text :class="[item.isSelsected? 'menu-item-text-active' : 'menu-item-text']">{{item.name}}</text>
        </div>
        <div class="bottom-placeholder"></div>
      </scroller>
      <div class="food">
        <div class="secondMenu" v-if="showSecondLevel.length>0">
          <scroller class="secondMenuInner" show-scrollbar="false" scroll-direction="horizontal">
            <div v-for="(item, index) in showSecondLevel" :key="index" class="secondMenuItem" @click="secondLevelTap(item.id,item.parentId)">
              <image class="secondMenuItemImage" :src="item.thumbnail"></image>
              <div class="secondMenuItemTextBox">
                <text :class="[item.isSelsected? 'secondMenuItemActive' : 'secondMenuItemText']">{{item.name}}</text>
              </div>

            </div>
          </scroller>
        </div>
        <scroll-view
            class="thirdMenu"
            ref="reflectName"
            pullTips="false"
            @pullLoadListener="onloading">
          <div v-for="(item, index) in thirdLevelInfo" :key="index">
            <div class="food-layer">
              <text class="food-layer-text">{{item.productCategoryName}}</text>
            </div>

            <div v-for="(productListItem, findex) in item.productList"  :class="[findex == 0?'food-item-first':'food-item']" :key="findex" @click="detailsClick(productListItem.id)">

              <!--            <column v-if="productListItem.point == 0" :product="productListItem"></column>-->
              <!--            <columnProduct v-else :product="productListItem"></columnProduct>-->

              <image class="food-item-picture" :src="productListItem.thumbnail"></image>

              <!--						<div class="food-item-info">-->
              <!--							<text class="food-item-title">{{productListItem.name}}</text>-->
              <!--							<div class="food-item-price">-->
              <!--								<text class="food-item-money">￥{{productListItem.price}}</text>-->
              <!--                <text class="title2 food-item-add" @click="addProductToCart(productListItem.id)">&#xe7a9;</text>-->
              <!--							</div>-->
              <!--						</div>-->

              <div class="food-item-info" style="display: flex;flex-direction: column;justify-content: space-between;">
                <div>
                  <text class="food-item-title">{{productListItem.name}}</text>
                </div>

                <!--                  <div class="food-item-price" v-if="productListItem.point ==0">-->
                <!--                    <text class="food-item-money">￥{{productListItem.price}}</text>-->
                <!--                    <text class="title2 food-item-add" @click="addProductToCart(productListItem.id)">&#xe7a9;</text>-->
                <!--                  </div>-->


                <div class="column_product_price_box">
                  <vip :profitTransfer="profitTransfer" :product="productListItem" :tranString="280" :promotions="productListItem.promotions" :marketPrice="productListItem.marketPrice" :price="productListItem.price"
                       :vipPrice="productListItem.vipPrice" :point="productListItem.point"></vip>
                  <div class="shoppingCartBox" @click="addProductToCart(productListItem.id)" >
                    <div class="shoppingCart">
                      <text class="addIcon">&#xe620;</text>
                    </div>
                  </div>
                </div>

              </div>


            </div>
          </div>
          <div class="showNoMore" v-if="showNoMore"><text>---- 到底了！----</text></div>
        </scroll-view>
      </div>
    </div>

    <!--<div class="bottom" @click="toCart">-->
    <!--<div class="bottomInner">-->
    <!--<text class="title2 bottom-box-cart-icon">&#xe7a9;</text>-->
    <!--<text v-if="count > 0" class="bottom-box-cart-num">{{count>99?'...':count}}</text>-->
    <!--</div>-->
    <!--<text :class="[count > 0 ? 'bottom-info-price' : 'bottom-info-price-not']">￥{{amount}}</text>-->
    <!--</div>-->

    <bottomFrame ref="bottomFrame" class="bottomFrame" @selectedInfo="selectedInfo"></bottomFrame>
  </div>
</template>

<style scoped>
.app {
  flex: 1;
}

.app-inner{
  flex: 1;
  flex-direction: row;
}
.header {
  position: relative;
  background-color: #f3f5f7;
}

.tabbar {
  flex: 1;
  margin-bottom: -2px;
}

.search_input_content {
  width: 710px;
  height: 58px;
  /* border: 1px solid rgba(212, 215, 220, 1); */
  opacity: 0.95;
  border-radius: 50px;
  display: flex;
  margin-left: 20px;
  flex-direction: row;
  align-items: center;
  background-color: white;
  overflow: hidden;
  margin-top: 20px;
  margin-bottom: 20px;
}

.icon {
  width: 50px;
  height: 50px;
  margin-left: 20px;
  margin-right: 20px;
}

.search_input_content-text{
  font-size: 30px;
  color: rgba(165, 165, 165, 0.705);
}
.menu {
  flex: 2;
  background-color: #ffffff;
}

.menu-item,
.menu-item-active {
  flex-direction: row;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  height: 112px;
  background-color: #ffffff;
}

.menu-item-active {
  background-color: #f3f5f7;
}

.menu-item-label {
  width: 24px;
  height: 24px;
  margin-right: 6px;
}

.menu-item-text,
.menu-item-text-active {
  flex: 1;
  color: #666666;
  text-align: center;
  font-size: 24px;
  text-overflow: ellipsis;
  lines: 2;
}

.menu-item-text-active{
  color: #f01414;
}

.food {
  flex: 7;
}

.secondMenu {
  width: 580px;
  height:120px;
  /* flex: 1; */
  padding-right: 10px;
  background-color: #f3f5f7;
}

.secondMenuInner {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.secondMenuItem {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 120px;
  margin-right: 10px;
  height: 140px;
}

.secondMenuItemImage {
  width: 75px;
  height: 75px;
  border-radius: 35px;
}

.secondMenuItemTextBox{
  /* border-style: solid;
  border-color: black;
  border-width: 1px; */
  height: 30px;
  overflow: hidden;
}

.secondMenuItemText {
  font-size: 25px;
  text-align: center;
}

.secondMenuItemActive {
  font-size: 25px;
  color: #f01414;
  text-align: center;
}

.thirdMenu {
  flex: 10;
  background-color: #f3f5f7;
  padding-right: 10px;
}

.food-layer {
  justify-content: center;
  background-color: #f3f5f7;
  border-left-width: 4px;
  border-left-style: solid;
  border-left-color: #d9dde1;
  height: 52px;
}

.food-layer-text {
  color: #666666;
  font-size: 24px;
  padding-left: 28px;
}

.food-item {
  flex-direction: row;
  align-items: flex-start;
  margin-left: 10px;
  margin-bottom: 20px;
  background-color: white;
  border-radius: 16px;
  padding: 10px;
}

.food-item-first {
  flex-direction: row;
  align-items: flex-start;
  margin-left: 10px;
  background-color: white;
  border-radius: 16px;
  padding: 10px;
  margin-top: 20px;
  margin-bottom: 20px;
}

.food-item-picture {
  width: 200px;
  height: 200px;
  border-radius: 16px;
}

.food-item-info {
  margin-left: 20px;
  width: 320px;
  height: 210px;

  position: relative;
}

.food-item-title {
  color: #333333;
  font-size: 28px;
  font-family: PingFang SC;
  font-weight: 400;
  max-height: 80px;
  color: rgba(26, 26, 30, 1);
  line-height: 40px;
  lines: 2;
  text-overflow: ellipsis;
}

.food-item-desc {
  color: #999999;
  font-size: 22px;
  margin-top: 4px;
}

.food-item-extra {
  color: #999999;
  font-size: 22px;
  margin-top: 4px;
}

.food-item-price {
  width: 320px;
  flex-direction: row;
  align-items: center;
  position: absolute;
  bottom: 0;
}

.food-item-money {
  flex: 1;
  font-weight: bold;
  color: #f01414;
  font-size: 30px;
  margin-right: 16px;
}

.food-item-add {
  font-size: 48px;
  width: 50px;
  height: 50px;
  color: #00a0dc;
}

.food-item-number {
  color: #666666;
  font-size: 26px;
  text-align: center;
  padding: 0 3px;
}

.bottom {
  position: absolute;
  left: 0;
  bottom: 30px;
  /* width: 250px; */
  padding-right: 20px;
  height: 80px;
  flex-direction: row;
  align-items: center;
  border-top-right-radius: 40px;
  border-bottom-right-radius: 40px;
  /* justify-content: flex-end; */
  background-image: linear-gradient(to right, rgb(179, 178, 177), rgb(231, 231, 230));
}

.bottom-placeholder {
  width: 750px;
  height: 100px;
}

.bottomInner {
  width: 100px;
  height: 80px;
  position: relative;
  justify-content: center;
  align-items: center;
}

.bottom-box-cart-icon {
  font-size: 50px;
  color: #ffffff;
}

.bottom-box-cart-num {
  position: absolute;
  top: 0px;
  left: 50px;
  font-size: 20px;
  text-align: center;
  padding: 0 11px;
  height: 36px;
  line-height: 36px;
  color: #ffffff;
  background-color: #ff0000;
  border-radius: 18px;
  z-index: 100;
}



.bottom-info-price,
.bottom-info-price-not {
  color: #ff0000;
  font-size: 34px;
  font-weight: 600;
  padding-right: 20px;
  border-left-style: solid;
  border-left-width: 1px;
  border-left-color: #000;
  padding-left: 15px;
}

.bottom-info-price-not {
  color: #fff;
}

.bottom-info-desc {
  flex: 1;
  border-left-width: 2px;
  border-left-style: solid;
  border-left-color: #0b1b2b;
  padding-left: 20px;
  font-size: 24px;
  color: #999999;
}

.bottom-info-button,
.bottom-info-button-not {
  background-color: #00b43c;
  color: #ffffff;
  font-weight: 600;
  width: 210px;
  height: 112px;
  line-height: 112px;
  text-align: center;
  font-size: 24px;
}

.bottom-info-button-not {
  background-color: #333333;
  color: #999999;
}

.showNoMore{
  width: 550;
  height: 40px;
  align-items: center;
  justify-content: center;
}

.title2 {
  font-family: iconfont2;
}
.addIcon {
  font-size: 24px;
  color: white;
  font-family: iconfont2;
}
.shoppingCart {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-image: linear-gradient(to right, #F03215, #F4A319);
  display: flex;
  justify-content: center;
  align-items: center;
}
.column_product_price_newTitle {
  /*font-size: 36px;*/
  font-size: 28px;
  font-weight: bold;
  color: rgba(231, 91, 83, 1);
  margin-right: 10px;
  /* height: 36px; */
  line-height: 36px;
}
.shoppingCartBox {
  width: 36px;
  height: 36px;
  position: absolute;
  right: 0px;
  bottom: 0px;
}
.column_product_price_box {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
}
</style>

<script>
const eeui = app.requireModule('eeui');
const modal = weex.requireModule('modal');
import {list} from '../../../api/product'
import {productCategoryList} from '../../../api/productCategory'
import {count} from '../../../api/cart'
import {find as shopFind} from '@/api/shop'
import noData from "@/components/noData/noData.vue";
import bottomFrame from "@/components/bottomFrame/bottomFrame.vue";
import myNavbar from "../../../components/myNavbar/myNavbar.vue";
import columnProduct from '../../../components/productCoupons/column.vue'
import column from '../../../components/product/column.vue'
// import vip from '../../../components/product_activity/product_vip.vue'
import vip from '@/pages/member/nearbyShopsDetails/components/product_activity/product_vip.vue'
export default {
  components: {
    noData,
    bottomFrame,
    myNavbar,
    columnProduct,
    column,
    vip
  },
  data() {
    return {
      profitTransfer:'',
      sellerInfo: {},
      active: 0,
      lists: [],
      cartShow: false,
      cartNum: 0,
      cartMoney: 0,

      pageNum: 1,
      pageSize: 10,
      adSrc: "http://cdn.rzico.com/v4.0/test1.png",
      firstLevelInfo: [],
      showSecondLevel: [],
      productInfoCache: [], //缓存下一页的数据
      isShowSecond: true, //是否显示二级分类
      secondLevelInfo: [],
      thirdLevelInfo: [],
      currentFirstId: "",
      currentSecondId: "",
      currentFirstIndex: "", //目前被选中的一级分类下标
      currentSecondIndex: "", //目前被选中的二级分类下标

      firstLevelScrollTop: 0, //一级的纵向滑动位置
      secondLevelScrollLeft: 0, //二级的横向滑动位置
      toIndex: "",
      showNoMore:false,
      count:0,
      amount:0
    }
  },
  created() {
    this.initIconFont()
    let optionsId = app.config.params
    let _this = this
    this.getCategoryList(() => {
      //console.info("optionsId-*-" + optionsId)
      if (_this.isNull(optionsId)) {
        this.currentFirstId = this.firstLevelInfo[0].id
        this.firstLevelFun(this.currentFirstId, true)
      } else {
        //console.info("二级分类的数据secondLevelInfo-*-" + this.secondLevelInfo.length)
        let off = true
        if (this.firstLevelInfo.length > 0) {
          //console.info("this.firstLevelInfo-*-" + JSON.stringify(this.firstLevelInfo.length))
          this.firstLevelInfo.map((item, index) => {
            if (item.id == optionsId) {
              this.currentFirstId = optionsId
              off = false
              this.currentFirstIndex = index
              //console.info("this.currentFirstId-*-" + this.currentFirstId)
              this.firstLevelFun(this.currentFirstId, true,
                  // () => {this.getFirstHeight()} //设置锚点
              )
            }
          })
        }
        if (off) {
          //console.info("off-*-" + off)
          if (this.secondLevelInfo.length > 0) {
            this.secondLevelInfo.map(item => {
              if (optionsId == item.id) {
                //console.info("我被找到了--" + JSON.stringify(item))
                this.currentFirstId = item.parentId
                this.currentSecondId = item.id
                //为什么要一级请求后在二级请求
                this.firstLevelFun(this.currentFirstId, false, () => {
                  _this.secondLevelFun(this.currentSecondId, () => {
                    if (this.firstLevelInfo.length > 0) {
                      // //console.info("this.firstLevelInfo-*-" + JSON.stringify(this.firstLevelInfo))
                      this.firstLevelInfo.map((item, index) => {
                        if (item.id == this.currentFirstId) {
                          this.currentFirstIndex = index
                          // this.getFirstHeight() //设置锚点
                        }
                      })
                    }
                    if (this.showSecondLevel.length > 0) {
                      // //console.info("this.firstLevelInfo-*-" + JSON.stringify(this.firstLevelInfo))
                      this.showSecondLevel.map((item, index) => {
                        if (item.id == this.currentSecondId) {
                          this.currentSecondIndex = index
                          // this.getSecondHeight() //设置锚点
                        }
                      })
                    }
                  })
                })
              }
            })
            //console.info("我被找到了this.data.currentFirstId--" + this.currentFirstId)
          }
        }
      }
    })
    this.getProfitTransfer()
  },
  mounted() {
    var _this = this
    this.$refs.reflectName.setHasMore(true);
    _this.getCartCount()
  },
  methods: {
    getProfitTransfer() {
      let params = "1"
      shopFind(params).then(res => {
        this.profitTransfer = res.data.shop.profitTransfer
      })
    },
    //搜索框的点击事件
    searchClick() {
      eeui.openPage({
            url: 'root://pages/goods/search/index.js',
            statusBarType: 'immersion',
            statusBarStyle:false
          },
          (result) => {

          }
      );
    },
    detailsClick(id) {
      eeui.openPage({
        params: id,
        url: 'root://pages/goods/product/details.js',
        statusBarType: 'immersion',
        statusBarStyle:false,
      })
    },
    //获取分类列表的信息
    getCategoryList(callback) {
      let _this = this
      // //console.info("一级分类的数据app.globalDatachId-*-" + JSON.stringify(this.getGlobalData().mchId))
      productCategoryList({
        mchId: this.getGlobalData().mchId
      }).then(
          res => {
            //console.info("商品分类列表res*************************************************")
            // //console.info(res)
            if (res.type == 'success') {
              _this.formateDateFromFirstAndSecond(res.data)
              if (callback) {
                callback()
              }
            }
          }
      ).catch(error => {
        //console.info(error)
      })
    },
    //获取商品列表信息
    getProductrequest(id, isFirst, callback) {
      let _this = this
      //console.info("商品信息id--" + JSON.stringify(id))
      //console.info("isFirst--" + isFirst)
      let pageSize = _this.pageSize
      if (isFirst) { //首次请求多请求一组数据
        pageSize *= 2
        list({
          pageNum: _this.pageNum,
          pageSize: pageSize,
          mchId: this.getGlobalData().mchId,
          productCategoryId: id,
          sortField: "product_category_id"
        }).then(
            res => {
              //console.info("我是第一次请求的商品信息res--------------------------------")
              //console.info(res.type)
              //console.info("返回数据的长度"+res.data.data.length)
              if (res.type == 'success') {
                if (res.data.data.length > _this.pageSize) {
                  this.productInfoCache = res.data.data.slice(_this.pageSize)
                } else {
                  this.showNoMore= true
                }

                //console.info("缓存的商品信息res---------------")
                //console.info(this.productInfoCache.length)
                if (callback) {
                  callback(res.data.data.slice(0, _this.pageSize))
                  //console.info("显示出来的商品信息res---------------")
                  // //console.info(res.data.data.slice(0, _this.pageSize))
                }
                console.info("我是第一次请求的商品信息res--------------------------------")
                console.info("请求的总数据--"+res.data.data.length)
                console.info("缓存数据productInfoCache--"+this.productInfoCache.length)
              }
            }
        ).catch(error => {
          //console.info(error)
        })
      } else { //后续请求
        list({
          pageNum: _this.pageNum,
          pageSize: _this.pageSize,
          mchId: this.getGlobalData().mchId,
          productCategoryId: id,
          sortField: "product_category_id"
        }).then(
            res => {
              //console.info("我是后续请求的商品信息res--" )
              if (res.type == 'success') {
                console.info("原来缓存数据productInfoCache--"+this.productInfoCache.length)
                if (callback) {
                  callback(this.productInfoCache)
                }
                if(res.data.data.length > 0){
                  this.productInfoCache = res.data.data
                  //console.info("缓存的商品信息res---------------")
                  //console.info(JSON.stringify(this.productInfoCache.length))
                }else{
                  this.showNoMore= true
                  this.productInfoCache=[]
                }
                console.info("我是后续请求的商品信息res--------------------------------")
                console.info("请求的总数据--"+res.data.data.length)
                console.info("新缓存数据productInfoCache--"+this.productInfoCache.length)
              }
            }
        ).catch(error => {
          //console.info(error)
        })
      }
    },
    //整理一级和二级分类数据
    formateDateFromFirstAndSecond(data) {
      if (data.length > 0) {
        let firstLevelInfo = []
        let secondLevelInfo = []
        // ////console.info("一二级分类的数据data-*-" + JSON.stringify(data))
        data.map((item) => {
          let firstLevelInfoItem = {}
          firstLevelInfoItem.id = item.id
          firstLevelInfoItem.name = item.name
          firstLevelInfoItem.thumbnail = item.thumbnail
          firstLevelInfoItem.isShow = item.isShow
          firstLevelInfoItem.isSelsected = false
          firstLevelInfo.push(firstLevelInfoItem)
          if (item.childrens.length > 0) {
            item.childrens.map((item1) => {
              let secondLevelInfoItem = {}
              secondLevelInfoItem.parentId = item.id
              secondLevelInfoItem.id = item1.id
              secondLevelInfoItem.name = item1.name
              secondLevelInfoItem.thumbnail = this.thumbnail(item1.thumbnail, 75, 75)
              secondLevelInfoItem.isShow = item1.isShow
              secondLevelInfoItem.isSelsected = false
              secondLevelInfo.push(secondLevelInfoItem)
            })
          }
        })
        // //console.info("一级分类的数据firstLevelInfo-*-" + JSON.stringify(firstLevelInfo))
        // //console.info("二级分类的数据secondLevelInfo-*-" + JSON.stringify(secondLevelInfo))
        this.firstLevelInfo= firstLevelInfo,
            this.secondLevelInfo= secondLevelInfo
      }
    },
    //整理商品列表数据
    formateDateFromProductList(data, type, callback) {
      //console.info("type--" + type)
      //console.info("开始整理商品数据data--" + JSON.stringify(data.length))
      let thirdLevelInfoNew = []
      let thirdLevelIdList = []
      if (data.length > 0) {
        data.map((item) => {
          thirdLevelIdList.push(item.productCategoryId)
        })
        thirdLevelIdList = Array.from(new Set(thirdLevelIdList)); //父级id去重
        if (thirdLevelIdList.length > 0) {
          thirdLevelIdList.map((item) => {
            let thirdLevelInfoItem = {}
            thirdLevelInfoItem.productCategoryId = item
            thirdLevelInfoItem.productList = []
            data.map((item1) => {
              if (item == item1.productCategoryId) {
                thirdLevelInfoItem.productCategoryName = item1.productCategoryName
                let productListItem = {}
                productListItem.id = item1.id
                productListItem.marketPrice = item1.marketPrice
                productListItem.name = item1.name
                productListItem.price = item1.price
                productListItem.goodsId = item1.goodsId
                productListItem.thumbnail = this.thumbnail(item1.thumbnail, 200, 200)
                productListItem.stock = item1.stock
                productListItem.sku = item1.sku
                productListItem.maxLimit = item1.maxLimit
                productListItem.promotions = item1.promotions
                productListItem.coupons = item1.coupons
                productListItem.vipPrice = item1.vipPrice
                productListItem.point = item1.point
                thirdLevelInfoItem.productList.push(productListItem)
                // console.log("7777777777777777777777777777777777777")
                console.log(thirdLevelInfoItem)
              }
            })
            thirdLevelInfoNew.push(thirdLevelInfoItem)
          })
          // ////console.info("thirdLevelInfoNew--" + JSON.stringify(thirdLevelInfoNew))
        }
        let thirdLevelInfo = []
        if (type == "push") {
          thirdLevelInfo = this.thirdLevelInfo
          if (thirdLevelInfo.length > 0 && thirdLevelInfoNew.length > 0) {
            let thirdLevelInfoNewIdList = [] //暂存遍历未找到的三级分类
            thirdLevelInfoNew.map((item) => {
              let checkOff = true
              thirdLevelInfo.map((item1) => {
                if (item1.productCategoryId == item.productCategoryId) {
                  checkOff = false
                  if (item.productList) {
                    item.productList.map((item2) => {
                      item1.productList.push(item2)
                    })
                  }
                }
              })
              if (checkOff) {
                thirdLevelInfoNewIdList.push(item.productCategoryId)
              }
            })
            if (thirdLevelInfoNewIdList.length > 0 && thirdLevelInfoNew.length > 0) {
              thirdLevelInfoNewIdList.map((item) => {
                thirdLevelInfoNew.map((item1) => {
                  if (item == item1.productCategoryId) {
                    thirdLevelInfo.push(item1)
                  }
                })

              })
            }
          }
        } else {
          thirdLevelInfo = thirdLevelInfoNew
        }
        this.thirdLevelInfo = thirdLevelInfo
        // //console.info("thirdLevelInfo--" + JSON.stringify(this.thirdLevelInfo))
      } else {
        // this.thirdLevelInfo= []
      }
      if(callback){
        callback()
      }
    },

    //点击购物车事件
    addProductToCart(productid) {
      this.$refs.bottomFrame.showFrame(
          productid,
          "addCart"
      );
    },

    //属性选择弹窗完成后数据回传函数
    selectedInfo(data) {
      var _this = this
      eeui.toast
      ({
        message: "属性数据回收了--" + JSON.stringify(data),
        // gravity: 'middle'
      });
      // this.selectComponent('#addCart').touchOnGoods(this.eInfo);
      _this.getCartCount()
    },

    //获取购物车的数量信息
    getCartCount() {
      let data = {}
      data.uuid = this.getGlobalData().uuid
      count(data).then(
          res => {
            console.log("单件商品数据--" + JSON.stringify(res))
            if (res.type == 'success') {
              this.count= res.data.quantity,
                  this.amount= res.data.amount
            }
          }
      ).catch(error => {
        console.log(error)
      })
    },

    toCart() {
      eeui.openPage({
            url: 'root://pages/index.js',
            params:{tab:'cart'},
            statusBarType: 'immersion',
            statusBarStyle:false,
          },
          (result) => {

          }
      );
    },

    //一级分类的事件
    firstLevelFun(id, needGetProduct, callback) {
      let _this = this
      let isShowSecond = _this.isShowSecond
      //console.info("id--" + id);
      let firstLevelInfo = this.firstLevelInfo
      let secondLevelInfo = this.secondLevelInfo
      let showSecondLevel = []
      if (firstLevelInfo.length > 0) {
        firstLevelInfo.map((item) => {
          if (item.id == id) {
            // if (item.isSelsected == false) {
            item.isSelsected = true
            //console.info("开始发送请求");
            //发送请求
            if (needGetProduct) {
              _this.getProductrequest(id, true, (data) => {
                _this.formateDateFromProductList(data)
                this.pageNum = 2
              })
            }
            // else{
            //         _this.getProductrequest(id, false, (data) => {
            //                 _this.formateDateFromProductList(data)
            //         })
            // }

            // }
          } else {
            item.isSelsected = false
          }
        })
      }

      // //console.info("secondLevelInfo--" + JSON.stringify(secondLevelInfo))
      if (secondLevelInfo.length > 0) {
        secondLevelInfo.map((item) => {
          if (item.parentId == id) {
            item.isSelsected = false
            showSecondLevel.push(item)
          }
        })
        // //console.info("showSecondLevel--" + JSON.stringify(showSecondLevel))
        if (showSecondLevel.length > 0) {
          isShowSecond = true
          let toIndex = "secondLevel" + showSecondLevel[0].id
          this.toIndex= toIndex
        } else {
          isShowSecond = false
        }
        // //console.info("isShowSecond--" + JSON.stringify(isShowSecond))
      }else{
        isShowSecond = false
      }
      this.isShowSecond= isShowSecond
      this.firstLevelInfo= firstLevelInfo
      this.showSecondLevel= showSecondLevel
      if (callback) {
        callback()
      }
    },

    //一级分类的点击事件
    firstLevelTap(id) {

      this.pageNum = 1
      this.currentFirstId = id
      this.currentSecondId = ""
      this.productInfoCache= []
      this.thirdLevelInfo= []
      this.pageNum= 1
      this.showNoMore= false
      //console.info("一级分类点击的事件pageNum--" + this.pageNum)
      this.firstLevelFun(id, true)
    },

    //二级分类数据请求事件
    secondLevelFun(id, callback) {
      //console.info("id" + JSON.stringify(id));
      let _this = this
      let showSecondLevel = this.showSecondLevel
      //console.info("showSecondLevel" + JSON.stringify(showSecondLevel));
      if (showSecondLevel.length > 0) {
        showSecondLevel.map((item) => {
          // //console.info("item" + JSON.stringify(item));
          if (item.id == id) {
            // if (item.isSelsected == false) {
            item.isSelsected = true
            //console.info("开始发送请求");
            _this.getProductrequest(id, true, (data) => {
              _this.formateDateFromProductList(data)
              this.pageNum = 2
              if (callback) {
                callback()
              }
            })
            // }

          } else {
            item.isSelsected = false
          }
        })
      }
      this.showSecondLevel= showSecondLevel
      // this.$refs.myScroll.smoothScrollToPosition(0)
    },

    //二级分类点击事件
    secondLevelTap(id,parentid) {
      //console.info("二级点击事件id--" + id)
      //console.info("二级点击事件parentid--" + parentid)
      this.currentFirstId = parentid
      this.currentSecondId = id
      this.productInfoCache= []
      this.thirdLevelInfo= []
      this.pageNum= 1
      this.showNoMore= false
      this.secondLevelFun(id)
    },

    //上啦加载
    onloading() {
      let _this = this
      let showSecondLevel = this.showSecondLevel
      ////console.info("下拉刷新的时间被触发showSecondLevel--"+JSON.stringify(showSecondLevel))
      let selectIndex = ""
      let id = ""
      let checkNext = this.checkNext
      // if(this.productInfoCache.length == this.pageSize){
      let pageNum = this.pageNum
      pageNum++
      this.pageNum = pageNum
      if (this.isNull(this.currentSecondId)) {
        console.info("我是一级的上拉加载事件productInfoCache--"+this.productInfoCache.length)
        if (this.productInfoCache.length == this.pageSize) {
          console.info("我先添加商品再去请求数据")
          _this.formateDateFromProductList(this.productInfoCache, "push",()=>{
            _this.getProductrequest(this.currentFirstId, false)
          })
        } else {
          if (this.productInfoCache.length > 0) {
            console.info("我只添加商品")
            _this.formateDateFromProductList(this.productInfoCache, "push")
            console.info("我只添加商品")
            this.productInfoCache = []
            this.showNoMore= true
            console.info("我只添加商品")
          } else {
            console.info("我都没有商品可添加")
            this.showNoMore= true
            // this.$refs.reflectName.setHasMore(false);
            // this.$refs.myScroll.smoothScrollToPosition(0)
          }
        }
        // //console.info("缓存的数量--"+this.productInfoCache.length)
      } else {
        // //console.info("我是二级的上拉加载事件-------------------------")
        let currentIndex = ""
        // if (this.showSecondLevel.length > 0) {
        //         this.showSecondLevel.map((item, index) => {
        //                 if (item.id == this.currentSecondId) {
        //                         currentIndex = index
        //                 }
        //         })
        //         if (this.pageNum == 2) {
        //                 let showSecondLevel = this.showSecondLevel
        //                 showSecondLevel.map(item => {
        //                         if (item.id == this.currentSecondId) {
        //                                 item.isSelsected = true
        //                         } else {
        //                                 item.isSelsected = false
        //                         }
        //                 })
        //                 this.setData({
        //                         showSecondLevel: showSecondLevel
        //                 })
        //         }
        // }

        // //console.info("缓存的长度--" + this.productInfoCache.length)
        if (this.productInfoCache.length == this.pageSize) {
          _this.getProductrequest(this.currentSecondId, false, (data) => {
            _this.formateDateFromProductList(data, "push")
          })
        } else if (this.productInfoCache.length > 0) {
          _this.formateDateFromProductList(this.productInfoCache, "push")
          this.productInfoCache = []
          // //console.info(JSON.stringify(this.thirdLevelInfo))
          this.showNoMore= true
          // let scrollTop = this.scrollTop - 40
          // wx.pageScrollTo({
          // 	scrollTop: scrollTop,
          // 	duration: 300
          // })
        } else {
          this.showNoMore= true
          // this.$refs.reflectName.setHasMore(false);
          // let scrollTop = this.scrollTop - 40
          // wx.pageScrollTo({
          // 	scrollTop: scrollTop,
          // 	duration: 300
          // })
        }
      }
      this.$refs.reflectName.pullloaded();
    },

    //原来的部分
    selectMenu(index) {
      let position = 0;
      for (let i = 0; i < this.lists.length; i++) {
        if (i === index) {
          break;
        }
        position += this.lists[i].foods.length + 1;
      }
      this.active = index;
      // this.$refs.myScroll.scrollToPosition(position);
    },

    stateChanged(index, data) {
      //console.info("scroll-headerder的回调函数")
      //console.info(index)
      //console.info(data)
      if (data.status === "float") {
        this.active = index;
      }
    },

    calculate() {
      let number = 0;
      let money = 0;
      for (let i = 0; i < this.lists.length; i++) {
        let foods = this.lists[i].foods;
        for (let j = 0; j < foods.length; j++) {
          number += foods[j].selectNum;
          money += foods[j].selectNum * foods[j].price;
        }
      }
      this.cartNum = number;
      this.cartMoney = money;
    },

    cartClear() {
      for (let i = 0; i < this.lists.length; i++) {
        let foods = this.lists[i].foods;
        for (let j = 0; j < foods.length; j++) {
          if (foods[j].selectNum > 0) {
            this.$set(foods[j], 'selectNum', 0);
          }
        }
      }
      this.cartNum = 0;
      this.cartMoney = 0;
      this.cartShow = false;
    },

    cartCheck() {
      this.calculate();
      eeui.alert({
        title: "支付提示",
        message: "您需要支付" + this.cartMoney + "元",
      });
    }
  }
}
</script>
